package kamikazehero.game.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;

import javax.swing.JPanel;
import javax.swing.Timer;

import kamikazehero.constants.Constants;
import kamikazehero.game.entity.ControllableEntity;
import kamikazehero.game.window.GameWindow;
import net.java.games.input.Controller;
import net.java.games.input.Event;
import net.java.games.input.EventQueue;
import net.java.games.input.Rumbler;

@SuppressWarnings("serial")
public class TestView extends GameView {

	private Timer timer;
	private ControllableEntity entity0;
	private ControllableEntity entity1;
	private EventQueue eventQueue;
	private Event event;
	private Point point;
	private Thread thread0;
	private Thread thread1;
	public float x;
	public float y;
	Rectangle rect0;
	Rectangle rect1;
	public TestView(Controller controller, Dimension dimension) {
		super(controller, dimension);

		rect0 = new Rectangle(Constants.x, Constants.y, 20, 20);
		rect1 = new Rectangle(Constants.x, Constants.y + 50, 20, 20);
		timer = new Timer(30, new Animate());
		//thread0 = new Thread(entity0 = new ControllableEntity(this.controller, timer, Constants.x, Constants.y ));
		//thread1 = new Thread(entity1 = new ControllableEntity(this.controller, timer, Constants.x, Constants.y ));
		entity0 = new ControllableEntity(this.controller, timer, Constants.x, Constants.y );
		entity1 = new ControllableEntity(this.controller, timer, Constants.x, Constants.y );
		entity1.setZAxis(true);
		timer.start();
	}
	
	public void poll(){
		//thread0.run();
		//thread1.run();
	}
	
	public void paintComponent(Graphics graphics){
		super.paintComponent(graphics);
		Graphics2D g = (Graphics2D)graphics;
		
		g.draw(rect0);
		g.draw(rect1);
		//g.translate(entity.xCoord, entity.yCoord);
		
	}

	public class Animate implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			
				rect0.x = entity0.xCoord;
				rect0.y = entity0.yCoord;
				
				rect1.x = entity1.xCoord;
				rect1.y = entity1.yCoord;
			
			repaint();
		}
	}
	/*
	public void move(){
		
		event = new Event();
		point = new Point();
		String axis = null;
		
		while(true){
	
			controller.poll();
			eventQueue = controller.getEventQueue();
			
			while(eventQueue.getNextEvent(event)){
				
				if(event.getComponent().isAnalog()){
					axis = event.getComponent().getName();
				}
				
				if(axis.equals("x")  || axis.equals("X Axis")){
					x = event.getValue();
					System.out.println(x);
					//point.x += (int)Math.floor(x + 0.25f);
				}else if(axis.equals("y") || axis.equals("Y Axis")){
					y = event.getValue();
					//point.y += (int)Math.floor(y + 0.25f);
				}
				//this.translate(Math.round(x), Math.round(y));
			}
		}
	}
	*/
}


